﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseUI;
using Utility;
using Utility.Model;

namespace MsgCenter.Web.Pages.Role
{
    public partial class Option : BasePage
    {
        protected string strType = ParamsOfRequest.Request("type");
        protected string strGuID = ParamsOfRequest.Request("Guid");
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                if (strType == "Add")
                {
                    this.linkSave.Visible = true;
                    this.hidRoleID.Value = Guid.NewGuid().ToString();
                }
                else if (strType == "Edit")
                {
                    this.linkSave.Visible = true;
                    this.SetModelValue();
                }
                else if (strType == "Look")
                {
                    this.SetModelValue();
                    this.txtDes.ToReadOnly();
                    this.txtName.ToReadOnly();
                    this.chkIsAdmin.Disabled = true;
                }
            }
        }

        private void SetModelValue()
        {
            this.hidRoleID.Value = strGuID.ToSafeString();
            Sys_Role model = BLL.BLLServiceHelper.GetRoleService().GetModel(strGuID.ToSafeString());
            if (model != null)
            {
                this.txtName.Value = model.RoleName;
                this.txtDes.Text = model.RoleDes;
                if (model.IsAdmin != null)
                {
                    this.chkIsAdmin.Checked = model.IsAdmin.Value;
                }
            }
        }
    }
}